﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_HelpNava_Add : System.Web.UI.Page
{
    public int HelpID
    {
        get { return Convert.ToInt32(ViewState["_HelpID"]); }
        set { ViewState["_HelpID"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDrpDownValue();
            HelpID = DongDong.Common.Misc.GetQueryStringAsInt("HelpID");
            if (HelpID != 0)
            {
                PopulateHelpDes();
            }

        }
    }
    public void PopulateHelpDes()
    {
        HelpDes objDes = HelpDes.Get(HelpID);
        if (objDes != null)
        {
            txtBiaoTi.Text = objDes.Title;
            txtNeiRong.Text = objDes.Des;
            drpHelpNav.SelectedValue = objDes.NavaID.ToString();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        HelpDes objHelpDes = new HelpDes();
        if (HelpID != 0)
        {
            objHelpDes = HelpDes.Get(HelpID);
        }
        objHelpDes.NavaID = DongDong.Common.Misc.ConvertToInt(drpHelpNav.SelectedValue);
        objHelpDes.Title = txtBiaoTi.Text;
        objHelpDes.Des = txtNeiRong.Text;
        if (HelpID != 0)
        {
            objHelpDes.Update();
            DongDong.Common.MessageBox.Show(this, "修改成功");

        }
        else
        {
            objHelpDes.Rank = System.DateTime.Now;
            objHelpDes.Add();
            DongDong.Common.MessageBox.ShowAndRedirect(this, "修改成功", "Add.aspx");

        }
    }

    public void GetDrpDownValue()
    {
        drpHelpNav.DataSource = HelpNava.GetAll();
        drpHelpNav.DataValueField = "ID";
        drpHelpNav.DataTextField = "Title";
        drpHelpNav.DataBind();
    }
}